package com.xxx.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xxx.common.Code;
import com.xxx.common.Result;
import com.xxx.pojo.ShoppingCart;
import com.xxx.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shop")
public class ShoppingCartController {


    @Autowired
    private ShoppingCartService service;

    @PostMapping("/save")
    public Result saveShop(@RequestBody List<ShoppingCart> cartList){

        boolean b = service.saveBatch(cartList);

        return b ? new Result(null, Code.SAVE_OK) : new Result(null,Code.SAVE_ERR,"系统内部错误！！！");
    }


    @GetMapping("/shopCart")
    public Result getShop(Long id){
        List<ShoppingCart> cartList = service.list(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getUserId, id));
        return new Result(cartList,Code.GET_OK);
    }

}
